<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:replace="common :: header"/>
<body>
<div class="page">
    <div class="card">
        <div class="card-header">
            <form id="search_form">
                <input class="easyui-textbox" data-options="label:'帐号'" name="loginName" style="width:180px;">
                <input class="easyui-textbox" data-options="label:'IP'" name="ipaddr" style="width:160px;">
                <input class="easyui-datebox" data-options="label:'时间',editable:false" name="params[beginTime]" style="width:160px;">
                - <input class="easyui-datebox" data-options="editable:false" name="params[endTime]" style="width:120px;">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onclick="dm.resetForm('search_form');">重置</a>
                <a href="#" class="easyui-linkbutton button-info" data-options="iconCls:'icon-search'" onclick="dm.search('table', 'search_form')">查询</a>
                <a shiro:hasPermission="monitor:loginLog:export" href="#" class="easyui-linkbutton" style="margin-left: 10px"
                   data-options="iconCls:'icon-save'" onclick="exportExcel()">导出</a>
            </form>
        </div>
        <div class="card-body">
            <div id="table"></div>
            <div id="toolbar" style="display: none">
                <a shiro:hasPermission="monitor:loginLog:remove" href="#" onclick="delLog()" class="easyui-linkbutton"
                   data-options="iconCls:'icon-cancel',plain:true">删除</a>
                <a shiro:hasPermission="monitor:loginLog:remove" href="#" onclick="cleanLog()" class="easyui-linkbutton"
                   data-options="iconCls:'icon-cancel',plain:true">清空</a>
                <a shiro:hasPermission="monitor:loginLog:unlock" href="#" onclick="unlock()" class="easyui-linkbutton"
                   data-options="iconCls:'icon-lock',plain:true">解除锁定</a>
            </div>
        </div>
    </div>
</div>
<script th:inline="javascript">
    $(function() {
        $('#table').datagrid({
            url: '/monitor/loginLog/list',
            fit: true,
            fitColumns: true,
            nowrap: true,
            pagination: true,
            pageSize: 20, // 每一页多少条数据
            pageList: [ 10, 20, 30, 40, 50 ], // 可以选择的每页的大小的combobox
            idField: 'logId',
            sortName: 'logId',
            sortOrder: 'desc',
            toolbar: '#toolbar',
            onLoadSuccess:function(data){
                $("#table").datagrid("clearSelections");
            },
            columns:[ [
                {field: 'ck', checkbox: true },
                {field: 'loginName', title: '帐号', align:'center',width: 80},
                {field: 'ipaddr', title: 'IP地址', align:'center',width: 100},
                {field: 'loginLocation', title: '位置', align:'center',width: 60},
                {field: 'browser', title: '浏览器', align:'center',width: 60},
                {field: 'os', title: '操作系统', align:'center',width: 100},
                {field: 'msg', title: '操作信息', align:'center',width: 200, formatter:function (value) {
                        if (common.isEmpty(value))  return "登录成功";
                        else return value;
                }},
                {field: 'status', title: '结果', align:'center',width: 60, formatter:function (value) {
                    if (value == 0 ) return '<span class="layui-badge layui-bg-green">成功</span>';
                    if (value == 1 ) return '<span class="layui-badge">失败</span>';
                }},
                {field: 'loginTime',title: '登录时间',align:'center',sortable: true, width: 140,formatter: timeFormatter}
            ] ]
        });
    });

    function delLog() {
        dm.getRows('table', 'logId', function (ids) {
            dm.confirm('删除操作不可恢复。您确定要删除吗？', function () {
                dm.post('/monitor/loginLog/delete', {ids:ids}, function () {
                    dm.search('table');
                })
            })
        })
    }
    function cleanLog() {
        dm.confirm('清空操作不可恢复。您确定要清空登录日志吗？', function () {
            dm.post('/monitor/loginLog/clean', {}, function () {
                dm.search('table');
            })
        })
    }
    function unlock() {
        dm.getRow('table', function (row) {
            dm.post('/monitor/loginLog/unlock', {loginName:row.loginName}, function () {
                dm.search('table');
            })
        })
    }

    function exportExcel() {

    }

</script>
</body>
</html>
